package com.gdawj.controleur;

import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@ManagedBean
public class AuthentificationBean {

        // deconnecter l'utilisateur
        public String deconnexion()
        {
            String page="/authentification?faces-redirect=true";
            // informations d'authentification
            FacesContext context=FacesContext.getCurrentInstance();
            // recuperer l'objet request
            HttpServletRequest request=(HttpServletRequest)context.getExternalContext().getRequest();
            // recuperer l'objet session
            HttpSession session=(HttpSession)context.getExternalContext().getSession(true);
            try
            {
                session.invalidate();
                request.logout();
            }
            catch(ServletException ex)
            {
                ex.printStackTrace();
                page="/erreurauthentification?faces-redirect=true";
            }
            return page;
        }

}

